<template>
  <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <el-form :model="dialogModel" ref="addTemForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="name" label="阶段名称">
          <el-input v-model="dialogModel.name"></el-input>
        </el-form-item>
        <el-form-item prop="stageId" label="阶段排序">
          <el-select v-model="dialogModel.stageId" placeholder="请选择阶段" clearable size="default">
            <el-option v-for="item in stageId" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
  <!-- 上级部门弹框 -->
</template>

<script setup lang='ts'>
import { reactive, toRefs, onBeforeMount, onMounted, ref } from 'vue'
import useBaseTem from '@/composables/01work/02TemPlate/useBaseTem'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';

import { CheckListAdd } from '@/api/01work/01type'
import { ElForm } from 'element-plus'
import { EditType, Title } from '@/type/BaseEnum'
const { dialog, onClose, onShow } = useDialog()
const { rules, dialogModel } = useBaseTem()
const { global, proxy } = useInstance();

const addTemForm = ref<InstanceType<typeof ElForm>>();
const emit = defineEmits(['save'])
const confirm = () => {
  addTemForm.value?.validate(isOk => {
    if (isOk) {
      emit('save', dialogModel)
      onClose()
    }
  })
}
const props = defineProps({
  stageId: {
    type: [Array, Object],
    default: () => []
  }
})
const show = (type: string, row?: CheckListAdd) => {
  console.log('show');
  dialog.width = 650
  dialog.height = 150
  type == EditType.ADD ? dialog.title = Title.ADD : dialog.title = Title.EDIT
  onShow()
  global.$resetForm(addTemForm.value,dialogModel)
  if(type === EditType.EDIT){
    global.$objCopy(row,dialogModel)
  }
}
defineExpose({
  show
})
</script>
<style scoped lang='scss'></style>